package com.coszero.utils.utils

import android.app.Activity
import android.content.Context
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager

/**
 * @author xmqian
 * @date 2018/5/25
 * @desc 一些杂项的方法
 * @version 1
 */
object Utils {
    // 隐藏软件盘
    fun hiddeSoftInput(activity: Activity) {
        val inputMethodManager = activity
            .getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager

        if (activity.window.attributes.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
            if (activity.currentFocus != null) inputMethodManager.hideSoftInputFromWindow(
                activity
                    .currentFocus!!.windowToken,
                InputMethodManager.HIDE_NOT_ALWAYS
            )
        }
    }
}
